package net.hn.hnms.biz.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.hn.hnms.biz.project.domain.ProjectFile;
import net.hn.hnms.biz.project.domain.ProjectInfo;
import net.hn.hnms.biz.project.mapper.ComprehensiveQueryMapper;
import net.hn.hnms.biz.project.mapper.ProjectFileMapper;
import net.hn.hnms.biz.project.mapper.ProjectInfoMapper;
import net.hn.hnms.biz.project.request.ComprehensiveQueryReq;
import net.hn.hnms.biz.project.service.IComprehensiveQueryService;
import net.hn.hnms.biz.project.vo.ComprehensiveQueryVo;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 刘昊
 * @version 1.0.0
 * @ClassName ComprehensiveQueryServiceImpl.java
 * @Description 综合查询
 * @date 2024-03-19 9:58
 */
@Service
public class ComprehensiveQueryServiceImpl implements IComprehensiveQueryService {

    @Autowired
    private ComprehensiveQueryMapper comprehensiveQueryMapper;
    @Autowired
    private ProjectInfoMapper projectInfoMapper;
    @Autowired
    private ProjectFileMapper projectFileMapper;


    @Override
    public ResponsePage<ComprehensiveQueryVo> queryPageList(ComprehensiveQueryReq req, PageQuery pageQuery) {
        Page<ComprehensiveQueryVo> page = comprehensiveQueryMapper.queryPageList(pageQuery.build(),req);
        return new ResponsePage<>(page.getRecords(), page.getTotal());
    }

    @Override
    public R<ComprehensiveQueryVo> queryDetails(ComprehensiveQueryReq req) {

        ProjectInfo projectInfo = projectInfoMapper.selectById(req.getProjectId());
        if (projectInfo == null) {
            return R.fail("查询数据不存在");
        }
        ComprehensiveQueryVo queryVo = new ComprehensiveQueryVo();
        QueryWrapper<ProjectFile> wrapper = new QueryWrapper<>();
        wrapper.eq("project_id",req.getProjectId());
        List<ProjectFile> projectFile = projectFileMapper.selectList(wrapper);
        queryVo.setProjectFiles(projectFile);
        return R.ok(queryVo);

    }

}
